package com.wx.gof.pattern.behavioral.iterator;

/**
 * @ClassName Application
 * @Author wx
 * @Description 应用程序-迭代器设计模式
 * @Date 2018-12-12-22:53
 */
public class Application {
    public static void main(String[] agrs) {
        Course course1 = new Course("Java");
        Course course2 = new Course("C");
        Course course3 = new Course("C++");
        Course course4 = new Course("Python");
        Course course5 = new Course("算法");
        Course course6 = new Course("数据结构");


        CourseAggregate courseAggregate = new CourseAggregateImpl();

        courseAggregate.addCourse(course1);
        courseAggregate.addCourse(course2);
        courseAggregate.addCourse(course3);
        courseAggregate.addCourse(course4);
        courseAggregate.addCourse(course5);
        courseAggregate.addCourse(course6);

        System.out.println("-----课程列表-----");
        printCourses(courseAggregate);

        courseAggregate.removeCourse(course4);
        courseAggregate.removeCourse(course5);

        System.out.println("-----删除操作之后的课程列表-----");
        printCourses(courseAggregate);
    }

    public static void printCourses(CourseAggregate courseAggregate) {
        CourseIterator courseIterator = courseAggregate.getCourseIterator();
        while (courseIterator.hasNext()) {
            Course course = (Course) courseIterator.next();
            System.out.println(course.getName());
        }
    }
}
